Skip to main content

All Questions

Tagged with
2votes
1answer
42views

How to compute elementwise dot product of two 2D NumPy arrays [duplicate]

This script: import numpy as np a = np.array([[0, 1], [1, 1], [1, 0]]) b = np.array([[1, 0], [1, 1], [1, -1]]) dot = a[:, 0]*b[:, 0] + a[:, 1]*b[:, 1] print(dot) produces elementwise dot product of ...
Paul Jurczak's user avatar
2votes
1answer
85views

Why the performance is bad if I use HashMap to solve Codility problem MinAbsSum?

Regarding the Codility problem MinAbsSum at https://app.codility.com/programmers/lessons/17-dynamic_programming/min_abs_sum/, the performance is bad if I use HashMap to solve the problem. I expect the ...
James's user avatar
2votes
2answers
68views

Pandas: Fill in missing values with an empty numpy array

I have a Pandas Dataframe that I derive from a process like this: df1 = pd.DataFrame({'c1':['A','B','C','D','E'],'c2':[1,2,3,4,5]}) df2 = pd.DataFrame({'c1':['A','B','C'],'c2':[1,2,3],'c3': [np.array((...
cbw's user avatar
  • 289
-1votes
0answers
33views

Efficiently Finding the Indices of the N Largest Values in a NumPy Array Without Sorting the Entire Array [duplicate]

I'm working with very large NumPy arrays (millions to billions of elements) and need to find the indices of the N largest values in the array. Using np.argsort() followed by slicing to get the last N ...
rysch's user avatar
0votes
1answer
67views

Apparently weird condition on inclusion of endpoint in np.arange() [duplicate]

The numpy.arange function takes the three parameters: start, stop, step (positional args.) The default step is 1. Throughout my entire Numpy experience, the last element of the resultant array is not ...
VizDracViz's user avatar
2votes
1answer
103views

Why do these nearly identical functions perform very differently?

I have written four functions that modify a square 2D array in place, it reflects half of the square array delimited by two sides that meet and the corresponding 45 degree diagonal, to the other half ...
Ξένη Γήινος's user avatar
0votes
1answer
58views

nums[:] = unique anyone please explain this line of code [duplicate]

class Solution(object): def removeDuplicates(self, nums): unique = [] for num in nums: if num not in unique: unique.append(num) nums[:] ...
Siva Anchuri's user avatar
5votes
1answer
231views

Optimizing LeetCode's "Minimum Pair Removal to Sort Array II" Solution to Prevent Time Limit Exceeded Errors

I am working on the LeetCode problem 3510. Minimum Pair Removal to Sort Array II: Given an array nums, perform the following operation any number of times: Select the adjacent pair with the minimum ...
manhera's user avatar
4votes
1answer
171views

Efficient and readable way to get N-dimensional index array in C-order using NumPy

When I need to generate an N-dimensional index array in C-order, I’ve tried a few different NumPy approaches. The fastest for larger arrays but less readable: np.stack(np.meshgrid(*[np.arange(i, dtype=...
Olibarer's user avatar
2votes
2answers
68views

Numpy- strange behaviour of __setitem__ of array

Say we have an array: a = np.array([ [11, 12, 13], [21, 22, 23], [31, 32, 33], [41, 42, 43] ]) a[[1, 3], [0, 2]] = 0 So we want to set zeros to 0th and 2nd element at both 1st and ...
IzaeDA's user avatar
-4votes
0answers
61views

Save images to disk from array in python [duplicate]

I would like to also save the images in the array, I'm able to return them but not save them, I get AttributeError: 'Axes' object has no attribute 'array_interface' import random import matplotlib....
daffer's user avatar
-5votes
1answer
53views

Fastest and cleaner ways to insert, update, delete 2-dimensional array [duplicate]

I'm newbie in python language and have some prolem here. I have a list of name and score for example: score = [['Andy', 80], ['John', 70], ['Diana', 100]] I want to Delete or Update score based on it'...
Tommy Sayugo's user avatar
1vote
5answers
99views

Can I multiply these Numpy arrays without creating an intermediary array?

This script: import numpy as np a = np.linspace(-2.5, 2.5, 6, endpoint=True) b = np.vstack((a, a)).T c = np.array([2, 1]) print(b*c) produces: [[-5. -2.5] [-3. -1.5] [-1. -0.5] [ 1. 0.5] [ ...
Paul Jurczak's user avatar
0votes
1answer
21views

elasticsearch query with Python lists returns "Can't get text on a START_ARRAY at 1:30"

I'm new with elastic (any also with python) but have some first success: es = Elasticsearch(['http://localhost:9200'], basic_auth=('user', 'pw')) query_body = { "query": { "...
Andre Bergmann's user avatar
1vote
3answers
122views

numpy element-by-element subtract

I have two numpy 'arrays': 1st is a 2D array with shape (N, 2) 2nd is a 3D "matrix" with shape (N, M, 2) where M can be different from 0 to N-1 Code example import numpy as np a = np.array([...
Arno Kukk's user avatar

153050per page
close